/**
 * Created by zzy on 2018/2/8.
 */
import {NavigationActions} from 'react-navigation'

export function ResetRouter(navigation, routers=[]) {

    let actions = [];
    actions.push({
        routeName: 'Root',
        params: {}
    });

    for (router of routers) {
        if (router.name === 'Root'){
            continue;
        }
        actions.push({
            routeName: router.name,
            params: router.params || {}
        })
    }
    const resetAction = NavigationActions.reset({
        index: actions.length - 1,
        actions: actions
    })
    navigation.dispatch(resetAction)
}